package com.eqdd.yiqidian.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

import com.bumptech.glide.Glide;
import com.eqdd.yiqidian.base.GlideApp;

/**
 * @author吕志豪 .
 * @date 18-3-10  上午9:40.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class GlideRecyclerView extends RecyclerView {


    public GlideRecyclerView(Context context) {
        super(context);
        init();
    }

    public GlideRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();

    }

    public GlideRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();

    }

    private void init() {
        addOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (getContext() != null) {
                    switch (newState) {
                        case SCROLL_STATE_IDLE:
                            GlideApp.with(getContext()).resumeRequests();
                            break;
                        case SCROLL_STATE_DRAGGING:
                        case SCROLL_STATE_SETTLING:
                            GlideApp.with(getContext()).pauseRequests();
                            break;
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
            }
        });
    }
}
